package com.xunyoutest.shop.utils;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;

/**
 * admin
 * 2018/12/6
 * content : 剪贴板
 */
public class CopyManager {

    private static CopyManager sInstance;

    public static CopyManager getInstance() {
        if (sInstance == null) {
            sInstance = new CopyManager();
        }
        return sInstance;
    }

    private CopyManager() {
    }


    public void copyText(Context context, String text) {
        // 得到剪贴板管理器
        ClipboardManager clipboardManager =
                (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        assert clipboardManager != null;

        clipboardManager.setPrimaryClip(ClipData.newPlainText(null, text));
        if (clipboardManager.hasPrimaryClip()) {
            clipboardManager.getPrimaryClip().getItemAt(0).getText();
        }
    }


}

